<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="util.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
	int idProject = MiscUtil.getIntUrlParam(request, "idProject");
	String strSentFrom = MiscUtil.getStringUrlParam(request, "sentFrom");
	
	boolean hasProject = false;
	String projectName = "Unknown";
	String projectUrl = "";

	if (idProject != Integer.MIN_VALUE) {
		projectName = CacheUtil.getProjectName(idProject);
		projectUrl = "project.jsp?id=" + idProject;
		hasProject = true;
	}
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Create New Team Allocation</title>

<link rel="stylesheet" href="css/common.css" />
<link rel="stylesheet" href="css/inputForm.css" />
<link rel="stylesheet" href="css/listForm.css" />
<link rel="stylesheet" href="css/jquery-ui-1.8.14.custom.css" type="text/css" />
<link rel="stylesheet" href="css/hyjack.css" type="text/css" />
<link rel="stylesheet" href="css/datepicker.css" type="text/css" />
<link rel="stylesheet" href="css/themes/ui-lightness/jquery.ui.all.css" />
<link rel="stylesheet" href="css/jquery-ui-timepicker.css" type="text/css" />
<link rel="stylesheet" href="css/jquery-datepicker.css" />
<link rel="stylesheet" href="css/jquery-dialog.css" />

<script language="javascript" type="text/javascript" src="js/jquery.min.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.hyjack.select.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.ui.core.min.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.ui.widget.min.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.ui.timepicker.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.ui.datepicker.js"></script>
<script language="javascript" type="text/javascript" src="js/datepicker.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.hyjack.js"></script>
<script language="javascript" type="text/javascript" src="js/ajaxQuickInsert.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.ui.tools.min.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.numeric.js"></script>
<script language="javascript" type="text/javascript" src="js/common.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.14.custom.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-timepicker-addon.js"></script>

<link rel="stylesheet" href="css/inputForm.css" />

<script language="javascript" type="text/javascript">
	var requiredInputs = [['id_project','id_project_required'],['id_employee','id_employee_required'],['id_project_role','id_project_role_required']];
	var intInputs = [];
	var doubleInputs = [];
	var dateInputs = [];
	var timeInputs = [];

	function checkInputs() {
		var valid = true;

		if (checkRequiredInputs(requiredInputs) == false) {
			valid = false;
		}
		if (checkIntInputs(intInputs) == false) {
			valid = false;
		}
		if (checkDoubleInputs(doubleInputs) == false) {
			valid = false;
		}
		if (checkDateInputs(dateInputs) == false) {
			valid = false;
		}
		if (checkTimeInputs(timeInputs) == false) {
			valid = false;
		}

		// SPECIFIC VALIDATE CODE HERE		

		return valid;
	}
</script>
</head>
<body>
	<div class="divContainer">
		<%@ include file="menu.jsp"%>
		<form action="teamAllocation?mode=insert<%if (hasProject) {%>&id_project=<%=idProject%><%}%><%if (strSentFrom != "") {%>&sentFrom=<%=strSentFrom%><%}%>" method="post" onSubmit="return checkInputs();" onreset="return confirm('Do you really want to reset the form?')">
			<table class="tblInput">
				<%
					if (hasProject) {
				%>
				<tr>
					<td colspan="1"><b>Project: <a id="link_project" name="link_project" href="<%=projectUrl%>"><%=projectName%></a> </b></td>
				</tr>
				<%
					}
				%>
				<tr>
					<td class="inputHeader">CREATE NEW TEAM ALLOCATION</td>
				</tr>
				<tr>
					<td style="padding-left: 400px; padding-right: 400px;">
						<table cellspacing="0px">
							<%
								if (!hasProject) {
							%>
							<tr>
								<td colspan="3">
									<center>
										<i>(Select project in the below list)</i>
									</center></td>
							</tr>
							<tr class="trField">
								<td class="tdFieldName">Project</td>
								<td class="tdFieldInput" title="Project which new checklist belongs to."><select id="id_project" name="id_project" class="hyjack" title="Project which new checklist belongs to.">
										<%=HtmlUtil.genModelSelect(CacheUtil.getProjectList(),
						null, idProject)%>
								</select></td>
								<td class="tdErrMsg"></td>
							</tr>
							<%
								}
							%>
							<tr class="trField">
								<td class="tdFieldName">Phase</td>
								<td class="tdFieldInput"><select id="id_phase" name="id_phase" class="hyjack" title="Choose a phase for new allocation.">
										<%=HtmlUtil.genModelSelect(CacheUtil.getPhaseList(), null,
					Integer.MIN_VALUE, false, true)%>
								</select></td>
								<td class="tdErrMsg"><span id="id_phase_required" class="errMsg" style="display: none;">Id Phase is required</span> <span id="id_phase_invalid" class="errMsg" style="display: none;">Id Phase is invalid</span>
								</td>
							</tr>
							<tr class="trField">
								<td class="tdFieldName">Employee</td>
								<td class="tdFieldInput"><select id="id_employee" name="id_employee" class="hyjack" title="Choose an employee for new allocation.">
										<%=HtmlUtil.genModelSelect(CacheUtil.getEmployeeList(),
					null, Integer.MIN_VALUE, false, true)%>
								</select> <input class="btnAdd" type="button" id="addNewEmployee" value="" onclick="ajaxAddItem('#id_employee', 'employee', 'name', 'Please enter new employee name!');" title="Click here to add new employee." /></td>
								<td class="tdErrMsg"><span id="id_employee_required" class="errMsg" style="display: none;">Id Employee is required</span> <span id="id_employee_invalid" class="errMsg" style="display: none;">Id Employee is invalid</span>
								</td>
							</tr>
							<tr class="trField">
								<td class="tdFieldName">Project Role</td>
								<td class="tdFieldInput"><select id="id_project_role" name="id_project_role" class="hyjack" title="Choose an employee for new allocation.">
										<%=HtmlUtil.genModelSelect(CacheUtil.getProjectRoleList(),
					null, Integer.MIN_VALUE, false, true)%>
								</select> <input class="btnAdd" type="button" id="addNewProjectRole" value="" onclick="ajaxAddItem('#id_project_role', 'projectRole', 'name', 'Please enter new project role!');" title="Click here to add new project role" /></td>
								<td class="tdErrMsg"><span id="id_project_role_required" class="errMsg" style="display: none;">Id Project Role is required</span> <span id="id_project_role_invalid" class="errMsg" style="display: none;">Id Project Role is invalid</span>
								</td>
							</tr>
							<tr class="trField">
								<td class="tdFieldName">Description</td>
								<td class="tdFieldInput"><input class="inputText" type="text" id="description" name="description" maxlength="255" />
								</td>
								<td class="tdErrMsg"><span id="abb_name_required" class="errMsg" style="display: none;">Description is required</span> <span id="abb_name_invalid" class="errMsg" style="display: none;">Description is invalid</span>
								</td>
							</tr>
							<tr class="trField">
								<td class="tdFieldName">Remark</td>
								<td class="tdFieldInput"><input class="inputText" type="text" id="remark" name="remark" maxlength="255" />
								</td>
								<td class="tdErrMsg"><span id="abb_name_required" class="errMsg" style="display: none;">Remark is required</span> <span id="abb_name_invalid" class="errMsg" style="display: none;">Remark is invalid</span>
								</td>
							</tr>

							<tr class="trInputBottom">
								<td class="tdFieldName"></td>
								<td class="tdSubmit">
									<div class="divButtonSubmit">
										<input class="btnSubmit" type="submit" value="Submit" title="Click to save above information." />
									</div>
									<div class="divButtonReset">
										<input class="btnReset" type="reset" value="Reset" title="Click to reset all above fields." />
									</div>
									<div class="divButtonReset">
									<%
										String strBackLink = strSentFrom.equalsIgnoreCase("edit") ? ("project?mode=edit&id=" + idProject) : ("projectNew.jsp");
									%>
										<input class="btnReset" type="button" value="Finish" title="Click to finish adding" onclick="window.location.href='<%=strBackLink%>'"/>
									</div>
									<div style="clear: both;"></div></td>
							</tr>
						</table></td>
				</tr>
			</table>
		</form>
		<%
			String strIncludeURL = "teamAllocationList.jsp?idProject=" + idProject + "&embedded=true";
		%>
		<jsp:include page="<%=strIncludeURL%>"></jsp:include>
	</div>
</body>
</html>